<template>
  <MianBan title="人气推荐" fubiaoti="人气爆款 不容错过">
  <div ref="target" style="position: relative;height: 426px;">
      <!-- Transition vue组件的动画 -->
  <Transition name="fade">
    <ul class="goods-list" v-if="goods.length">
      <li v-for="item in goods" :key="item.id">
        <RouterLink to="/">
          <img :src="item.picture" alt="">
          <p class="name">{{item.title}}</p>
          <p class="desc">{{item.alt}}</p>
        </RouterLink>
      </li>
    </ul>
    <MianbanGujia bg="#fff" v-else/>
  </Transition>
  </div>
  </MianBan>
</template>

<script>
import MianBan from './MianBan-Panel '// 面板内容封装
import MianbanGujia from './MianbanGujia.vue'// 骨架效果
import { ref } from 'vue'
import { renqituijianqinqiu } from '@/Api/index'
import { lanjiazhai } from '@/components/hooks-lanjiazhai'

export default {
  name: 'HomeNew',
  components: { MianBan, MianbanGujia },
  setup () {
    // 原生写法
    // const goods = ref([])
    // renqituijianqinqiu().then(data => {
    //   goods.value = data.result
    // })
    // 数据懒加载 写法
    const target = ref(null)
    const result = lanjiazhai(target, renqituijianqinqiu)
    return { goods: result, target }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
